package com.buobao.oa.service;

import com.buobao.oa.dao.DepartmentDao;
import com.buobao.oa.dao.EmployeeDao;
import com.buobao.oa.dao.RbacDao;
import com.buobao.oa.dao.UserDao;
import com.buobao.oa.entity.Department;
import com.buobao.oa.entity.Employee;
import com.buobao.oa.entity.Node;
import com.buobao.oa.entity.User;
import com.buobao.oa.service.exceptions.BussinessException;
import com.buobao.oa.utils.MD5Utils;

import java.util.List;

public class UserService {
    private UserDao userDao = new UserDao();
    private RbacDao rbacDao = new RbacDao();

    /**
     * 验证用户
     * @param username
     * @param password
     * @return
     */
    public User checkLogin(String username, String password) {
        User user = userDao.selectUserByUsername(username);
        if (user!=null) {
            String checkPassword = MD5Utils.md5Digest(password,user.getSalt());
            if (user.getPassword().equals(checkPassword)) {
                return user;
            } else {
                throw new BussinessException("L002","密码错误");
            }
        } else {
            throw new BussinessException("L001","用户名不存在");
        }
    }

    public List<Node> getNodeListByUserId(long userId) {
        List<Node> result = rbacDao.selectNodesByUserId(userId);
        return result;
    }
}






















